Class Nur.MNISV3.Service.NurEmrConfig Extends %RegisteredObject [ Not ProcedureBlock ]
{

/// w ##class(Nur.MNISV3.Service.NurEmrConfig).GetCodeList("DHCNURHLJLDLR","","60000054")
ClassMethod GetCodeList(barCode = "", TCindentity = "", adm = "", pageInfo = "", specifyFileds = "", NurMPDataID, queryInfo, emrCode = "") As %String
{
    n (barCode,TCindentity , adm , pageInfo, specifyFileds, NurMPDataID, queryInfo,emrCode)
    s $zt="errorGetCodeList"
    s ^MML("GetCodeList",TCindentity_"-")=$lb(barCode,TCindentity , adm , pageInfo, specifyFileds, NurMPDataID, queryInfo,emrCode)
    i (TCindentity="")&&(emrCode'="") s TCindentity=##class(NurMp.Template).GetTCIndentity(emrCode)
    i +$g(NurMPDataID)=0 s NurMPDataID="" //处理字符
    i specifyFileds'="" {
        s specifyFileds=##class(Nur.MNISV3.Common.JSON).Decode(specifyFileds)
        s pageInfo="1^100"
        //最后返回不能是q ##class(NurMp.ErrorMsg).EncodeByWrite(Json)
        s str= ##class(NurMp.Template.Data.Find).GetData(TCindentity , adm , pageInfo, specifyFileds, NurMPDataID, queryInfo)
    }else{
        s specifyFileds=##class(%ListOfDataTypes).%New()
        s str= ##class(NurMp.TemplateSet).GetCodeList(TCindentity , adm , pageInfo, specifyFileds, NurMPDataID, queryInfo)
    }
    //所有医学表达式
    s funList= ##class(Nur.MNISV3.Service.NurEmrConfig).GetAll("","")
    s str=$replace(str,$c(0),"")
    s obj=##class(Nur.MNISV3.Common.JSON).Decode(str)
    d obj.SetAt(TCindentity,"TCindentity")
    d obj.SetAt(funList,"funList")
    q obj
errorGetCodeList
   w $ze,!
   q ##class(Nur.MNISV3.Common.Utils).ReturnMsgJson($ze,"999999","-1")
}

/// w ##class(Nur.MNISV3.Service.NurEmrConfig).GetXmlValuesString("DHCNURHLJLDLR","","60000054")
ClassMethod GetXmlValuesString(emrCode, id, episodeId = "", simplification = "")
{
    n (emrCode,id,episodeId,simplification)
    s $zt="errorGetXmlValuesString"
    s id=$replace(id,$c(0),"")
    s ^MML("GetXmlValuesString",emrCode)=$lb(emrCode,id,episodeId)
    s Msg="",Status="0" //定义初始值
    s Indentity=##class(NurMp.Template).GetTCIndentity(emrCode)
    s TCIndent=$ZConvert(Indentity,"U")
    s templateid=$o(^NurMp.TemplateI("TCIndentity"," "_TCIndent,""))
    q:$g(templateid)="" ""
    s tempalte=##class(NurMp.Template).%OpenId(templateid)
    s Indent=tempalte.Indentity
    s SaveType=tempalte.SaveType
    i SaveType="2"{
        i id'="" s objRecord=##class(NurMp.DHCTempMultData).%OpenId(id)
        e  s objRecord=""
    } else {
        s id=$o(^NurMp.DHCTempMultDataI("EmrCode"," "_TCIndent," "_episodeId,id),-1)
        s objRecord=##class(NurMp.DHCTempMultData).%OpenId(id)
    }
    //取模板xml
    set PrintTemplateId=$o(^NurMp.TemplateI("Indentity"," "_$ZConvert(emrCode,"U"),""))
    set PrintTemplate=##class(NurMp.Template).%OpenId(PrintTemplateId)
    set data = PrintTemplate.Content
    //s ret = $zcvt(data.Read(), "I", "UTF8")
    s ret = $zcvt(data.Read($zutil(96,39)), "I", "UTF8")

    s json=##class(%ArrayOfDataTypes).%New()
    d json.SetAt($g(msg),"msg")
    d json.SetAt($g(msgcode),"msgcode")
    d json.SetAt($g(Status),"status")
    //HISUI,表格加大宽度
    //i ret["HISUIDataTableElement"  d json.SetAt("888","docWidth") 
    //i emrCode="DHCNURTTLR" d json.SetAt("1288","docWidth") 
    d json.SetAt(ret,"data")
    //包含ZWNBSP--UTF-8有一个BOM(Byte Order Mark)的问题
    //d json.SetAt($e(ret,2,$l(ret)),"data")
    //i emrCode="DHCNURHLJLDLR" d json.SetAt("17","hideIds") ;隐藏指定ID
    //i (emrCode="DHCNURDHCNURXHPGDYYSC") d json.SetAt("#00000000","lineColor") ;透明
    // 是否打开最小宽度 默认""开启  1 关闭（单行显示）
    i (emrCode="DHCNURNYCFXPGLB")||(emrCode="DHCNURBWZZHZHLJLRR")||(emrCode="DHCNURADLLR"){
        d json.SetAt("1","openWidthFlag") //单行显示
    }
    q json

errorGetXmlValuesString
   w $ze,!
   q ##class(Nur.MNISV3.Common.Utils).ReturnMsgStream($ze,"999999","-1")
}

ClassMethod GetXmlValuesString2(emrCode, id, episodeId = "", simplification = "")
{
    n (emrCode,id,episodeId,simplification)
    s $zt="errorGetXmlValuesString2"
    s id=$replace(id,$c(0),"")
    s ^MML("GetXmlValuesString2",emrCode)=$lb(emrCode,id,episodeId)
    s Msg="",Status="0" //定义初始值
    s Indentity=##class(NurMp.Template).GetTCIndentity(emrCode)
    s TCIndent=$ZConvert(Indentity,"U")
    s templateid=$o(^NurMp.TemplateI("TCIndentity"," "_TCIndent,""))
    q:$g(templateid)="" ""
    s tempalte=##class(NurMp.Template).%OpenId(templateid)
    s Indent=tempalte.Indentity
    s SaveType=tempalte.SaveType
    i SaveType="2"{
        i id'="" s objRecord=##class(NurMp.DHCTempMultData).%OpenId(id)
        e  s objRecord=""
    } else {
        s id=$o(^NurMp.DHCTempMultDataI("EmrCode"," "_TCIndent," "_episodeId,id),-1)
        s objRecord=##class(NurMp.DHCTempMultData).%OpenId(id)
    }
    //取模板xml
    set PrintTemplateId=$o(^NurMp.TemplateI("Indentity"," "_$ZConvert(emrCode,"U"),""))
    set PrintTemplate=##class(NurMp.Template).%OpenId(PrintTemplateId)
    set data = PrintTemplate.Content
    //s ret = $zcvt(data.Read(), "I", "UTF8")
    s ret = $zcvt(data.Read($zutil(96,39)), "I", "UTF8")
    
    q ret //直接返回字符串
    
    s json=##class(%ArrayOfDataTypes).%New()
    d json.SetAt($g(msg),"msg")
    d json.SetAt($g(msgcode),"msgcode")
    d json.SetAt($g(Status),"status")
    //HISUI,表格加大宽度
    //i ret["HISUIDataTableElement"  d json.SetAt("888","docWidth") 
    //i emrCode="DHCNURTTLR" d json.SetAt("1288","docWidth") 
    d json.SetAt(ret,"data")
    //包含ZWNBSP--UTF-8有一个BOM(Byte Order Mark)的问题
    //d json.SetAt($e(ret,2,$l(ret)),"data")
    //i emrCode="DHCNURHLJLDLR" d json.SetAt("17","hideIds") ;隐藏指定ID
    //i (emrCode="DHCNURDHCNURXHPGDYYSC") d json.SetAt("#00000000","lineColor") ;透明
    // 是否打开最小宽度 默认""开启  1 关闭（单行显示）
    i (emrCode="DHCNURNYCFXPGLB")||(emrCode="DHCNURBWZZHZHLJLRR")||(emrCode="DHCNURADLLR"){
        d json.SetAt("1","openWidthFlag") //单行显示
    }
    q json

errorGetXmlValuesString2
   w $ze,!
   q ##class(Nur.MNISV3.Common.Utils).ReturnMsgStream($ze,"999999","-1")
}

/// w ##class(Nur.MNISV3.Service.NurEmrConfig).SetSignaturePadV4("DHCNURHLJLDLR","","60000054")
ClassMethod SetSignaturePadV4(base64 = "", userId = "", wardId = "") As %String
{
    n (base64,userId , wardId)
    s $zt="errorSetSignaturePadV4"
    s ^MML("SetSignaturePadV4",userId_"-"_$h)=$lb(base64,userId , wardId)
    s Msg="",Status="0" //定义初始值
    
    q ##class(Nur.MNISV3.Common.Utils).ReturnMsgJson(Msg,"999999",Status)
errorSetSignaturePadV4
   w $ze,!
   q ##class(Nur.MNISV3.Common.Utils).ReturnMsgJson($ze,"999999","-1")
}

/// w ##class(Nur.MNISV3.Service.NurEmrConfig).GetXmlValues("DHCNURHZRYHLPGD1","","27")
ClassMethod GetXmlValues(emrCode, id, episodeId = "", currHeadDr = "", userId = "", simplification = "", locId = "", hospitalId = "")
{
    n (emrCode,id,episodeId,currHeadDr,userId,simplification,locId,hospitalId,%session)
    s id=$replace(id,$c(0),"")
    s ^MML("GetXmlValues",emrCode)=$lb(emrCode,id,episodeId,currHeadDr,userId,simplification,locId,hospitalId)
    k tmp
    s $zt="errorGetPrintXmlValues"
    set Msg="",Status="0" //定义初始值
    
    s templateid=""
    s Indentity=##class(NurMp.Template).GetTCIndentity(emrCode)
    s TCIndent=$ZConvert(Indentity,"U")
    s templateid=$o(^NurMp.TemplateI("TCIndentity"," "_TCIndent,templateid))
    q:templateid="" ""
    s headDrItem= ##class(Nur.MNISV3.Service.NurEmr).GetDTTObj(episodeId,TCIndent,locId,hospitalId).GetAt("FormName") ;..GetChangeHeadObj(emrCode,episodeId,userId).GetAt("FormName")

    w headDrItem,!
    s tempalte=##class(NurMp.Template).%OpenId(templateid)
    s Indent=tempalte.Indentity
    s SaveType=tempalte.SaveType
    i SaveType="2"{
        i id'="" s objRecord=##class(NurMp.DHCTempMultData).%OpenId(id)
        e  s objRecord=""
    }
    else
    {
        s id=$o(^NurMp.DHCTempMultDataI("EmrCode"," "_TCIndent," "_episodeId,id),-1)
        s objRecord=##class(NurMp.DHCTempMultData).%OpenId(id)
    }
    //i id'="" s objRecord=##class(NurMp.DHCTempMultData).%OpenId(id)
    //e  s objRecord=""
    
    s TemplateIndentity=""   //input取值，从直接调用打印模板界面取值记录单，则是列表界面
    
    s tableArray=##class(%ListOfDataTypes).%New()  //存储所有table集合
    s ElementBaseArray=##class(%ListOfDataTypes).%New()  //存储所有input元素集合
    s ElementSets=##class(%ListOfDataTypes).%New()  //存储级联配置
    s statisticsList=##class(%ListOfDataTypes).%New() //存储统计配置           
    s StrictCodeList=##class(%ListOfDataTypes).%New()  //严格模式
    s PdaIsHide="true"
    //取模板xml
    set PrintTemplateId=$o(^NurMp.TemplateI("Indentity"," "_$ZConvert(emrCode,"U"),""))
    set PrintTemplate=##class(NurMp.Template).%OpenId(PrintTemplateId)
    set data = PrintTemplate.Content
    ;w data,!
    //固定格式
    set status=##class(%XML.TextReader).ParseStream(data,.textreader,"",27,1023,"",1)
    if ($$$ISERR(status)) s textreader=""
    quit:textreader="" ""    ;格式不对
    s lastSaveItem="",containerFlag=""
    k parent
    s RadioElementList=##class(%ListOfDataTypes).%New()
    s RadioElementValue=##class(%ArrayOfDataTypes).%New()

    s dynaNum = 0
    s IsDynamicTitle = "false"

    ;b ;54
    while textreader.Read()
    {
        if (textreader.Name = "ElementBase")
        {
            do textreader.MoveToAttributeName("type")
            
            if ((textreader.Value = "HiddenTextElement")||(textreader.Value = "TableElement")||(textreader.Value = "TableRowElement")||(textreader.Value = "TableCellElement")||(textreader.Value = "ContainerElement")||(textreader.Value = "LinkElement")||(textreader.Value = "LableElement")||(textreader.Value = "DropListElement")||(textreader.Value = "DropRadioElement")||(textreader.Value = "DropCheckboxElement")||(textreader.Value = "TimeElement")||(textreader.Value = "DateElement")||(textreader.Value = "TextElement")||(textreader.Value = "NumberElement")||(textreader.Value = "TextareaElement")||(textreader.Value = "LableElement")||(textreader.Value = "MutiLableElement")||(textreader.Value = "RadioElement")||(textreader.Value = "CheckElement")||(textreader.Value = "ButtonElement"))&&(textreader.NodeType [ "attribute")
            {
                 
                //评估单部分解析
                //解析元素：DropListElementPrint，DropRadioElementPrint，DropCheckboxElementPrint，TimeElementPrint，
                //DateElementPrint，TextElementPrint，NumberElementPrint，TextareaElementPrint，属性包括：Id，SaveField，SaveField
                s (Id,SaveField,DataSourceRef,FormName,NameText,Element,CascadingInfo,BindingTemplateID,GatherImportMapEffects,CallBackReturnMapEffects,CallBackEffects,ParentId,DoctorAdviceRule,FoundationJS)=""
                s (MaxWarning,MinWarning,MaxError,MinError) = ""
                s OprationItemList=##class(%ListOfDataTypes).%New()
                s OprationItemStr=""
                i textreader.Value'="" s Element=textreader.Value
                
                while textreader.Read()
                {
                    
                    //input控件Id
                    if (textreader.Name = "Id") && (textreader.NodeType'="endelement")
                    {
                        d textreader.Read()
                        if CascadingInfo=""  s Id=textreader.Value  //级联中的ID不取
                    }
                    //input控件保存字段
                    if (textreader.Name = "SaveField") && (textreader.NodeType'="endelement")
                    {
                        d textreader.Read()
                        s SaveField=textreader.Value
                    }
                    //input控件数据源
                    if (textreader.Name = "DataSourceRef") && (textreader.NodeType'="endelement")
                    {
                    
                        d textreader.Read()
                        s DataSourceRef=textreader.Value
                    }
                    //取转科科室用到
                    if (textreader.Name = "NameText") && (textreader.NodeType'="endelement")
                    {
                        d textreader.Read()
                        s NameText=textreader.Value
                        s tmpName("Id"," "_Id)=NameText
                    }
                    if (textreader.Name = "BasicInfo")
                    {
                        do textreader.MoveToAttributeName("type")
                        if (textreader.Value = "ContainerInfo") s containerFlag=1,containerId(Id)=1
                    }
                    if (textreader.Name = "Items") && (textreader.NodeType'="endelement")
                    {
                        s OprationItemList=##class(%ListOfDataTypes).%New()
                        s OprationItemData=##class(%ArrayOfDataTypes).%New()
                        s OprationItemStr=""
                        while textreader.Read()
                        {
                            if ((textreader.Name="MedicalInfoItem")||(textreader.Name="OprationItem"))&(textreader.NodeType'="endelement")
                            {
                                s OprationItemData=##class(%ArrayOfDataTypes).%New()
                            }
                            if (textreader.Name="Items")&(textreader.NodeType="endelement")  q
                            i textreader.Name'="" s OprationItemDesc=textreader.Name
                            i textreader.NodeType="chars"
                            {
                                i $g(OprationItemDesc)="" s OprationItemDesc=textreader.Value
                                d OprationItemData.SetAt(textreader.Value,OprationItemDesc)
                                s OprationItemStr=$s(OprationItemStr="":textreader.Value,1:OprationItemStr_textreader.Value)
                            }
                            if ((textreader.Name="MedicalInfoItem")||(textreader.Name="OprationItem"))&(textreader.NodeType="endelement")
                            {
                                d OprationItemList.Insert(OprationItemData)
                            }
                            
                        }
                        if (textreader.MoveToAttributeName("Value"))  
                    }
                    if (textreader.Name = "FormName") && (textreader.NodeType'="endelement")
                    {
                        d textreader.Read()
                        s FormName=textreader.Value
                    }

                    if (textreader.Name = "DynamicTitleLoad") && (textreader.NodeType'="endelement")
                    {
                        d textreader.Read()
                        s IsDynamicTitle=textreader.Value
                        ;w IsDynamicTitle,!
                    }

                    if (textreader.Name = "MEName") && (textreader.NodeType'="endelement")
                    {
                        d textreader.Read()
                        s MEName=textreader.Value
                    }
                    //数值控制
                    if (textreader.Name = "PointLen") && (textreader.NodeType'="endelement")
                    {
                        d textreader.Read()
                        s PointLen=textreader.Value
                    }
                    if (textreader.Name = "MaxWarning") && (textreader.NodeType'="endelement")
                    {
                        d textreader.Read()
                        s MaxWarning=textreader.Value
                    }
                    if (textreader.Name = "MinWarning") && (textreader.NodeType'="endelement")
                    {
                        d textreader.Read()
                        s MinWarning=textreader.Value
                    }
                    if (textreader.Name = "MaxError") && (textreader.NodeType'="endelement")
                    {
                        d textreader.Read()
                        s MaxError=textreader.Value
                    }
                    if (textreader.Name = "MinError") && (textreader.NodeType'="endelement")
                    {
                        d textreader.Read()
                        s MinError=textreader.Value
                    }
                    //跳转用
                    if (textreader.Name = "CallBackEffects") && (textreader.NodeType'="endelement")
                    {
                        d textreader.Read()
                        s CallBackEffects=textreader.Value
                        s tmpName("CallBackEffects"," "_Id)=CallBackEffects
                    }
                    if (textreader.Name = "CallBackReturnMapEffects") && (textreader.NodeType'="endelement")
                    {
                        d textreader.Read()
                        s CallBackReturnMapEffects=textreader.Value
                        s tmpName("CallBackReturnMapEffects"," "_Id)=CallBackReturnMapEffects
                    }
                    if (textreader.Name = "GatherImportMapEffects") && (textreader.NodeType'="endelement")
                    {
                        d textreader.Read() 
                        s GatherImportMapEffects=textreader.Value
                        s tmpName("GatherImportMapEffects"," "_Id)=GatherImportMapEffects
                    }
                    if (textreader.Name = "BindingTemplateID") && (textreader.NodeType'="endelement")
                    {
                        d textreader.Read()
                        s BindingTemplateID=textreader.Value
                        s tmpName("BindingTemplateID"," "_Id)=BindingTemplateID
                    }
                    if (textreader.Name = "Signature") && (textreader.NodeType'="endelement")
                    {
                        d textreader.Read()
                        s Signature=textreader.Value
                    }
                    if (textreader.Name = "SignatureAuto") && (textreader.NodeType'="endelement")
                    {
                        d textreader.Read()
                        s SignatureAuto=textreader.Value
                    }
                    //end
                    if (textreader.Name = "FoundationJS") && (textreader.NodeType'="endelement")
                    {
                        d textreader.Read()
                        s FoundationJS=textreader.Value
                    }
                    if (textreader.Name = "LableFor") && (textreader.NodeType'="endelement")
                    {
                        d textreader.Read()
                        s LableFor=textreader.Value
                    }
                    if (textreader.Name = "DoctorAdviceRule") && (textreader.NodeType'="endelement")
                    {
                        d textreader.Read()
                        s DoctorAdviceRule=textreader.Value
                    }
                    if (textreader.Name = "IsRequired") && (textreader.NodeType'="endelement")
                    {
                        d textreader.Read()
                        s Required=textreader.Value
                    }
                    if (textreader.Name = "ToolTipText") && (textreader.NodeType'="endelement")
                    {
                        d textreader.Read()
                        s ToolTipText=textreader.Value
                    }
                    
                    if (textreader.Name = "IsHide") && (textreader.NodeType'="endelement")
                    {
                        d textreader.Read()
                        s IsHide=textreader.Value
                    }
                    if (textreader.Name = "Disable") && (textreader.NodeType'="endelement")
                    {
                        d textreader.Read()
                        s Disable=textreader.Value
                    }
                    if (textreader.Name = "ParentId") && (textreader.NodeType'="endelement")
                    {
                        d textreader.Read()
                        s ParentId=textreader.Value
                        s parent(Id)=ParentId
                    }
                    if (textreader.Name = "GatherEffects") && (textreader.NodeType'="endelement")
                    {
                        d textreader.Read()
                        s GatherEffects=textreader.Value
                    }
                    if (textreader.Name = "GatherImportMapEffects") && (textreader.NodeType'="endelement")
                    {
                        d textreader.Read()
                        s GatherImportMapEffects=textreader.Value
                    }

                    if (textreader.Name = "StatisticsInfo") && (textreader.NodeType'="endelement")
                    {
                        s statisticsData=##class(%ArrayOfDataTypes).%New()
                        d statisticsData.SetAt($g(Id),"Id")
                        s statisticsDesc=""
                        while textreader.Read()
                        {
                            if (textreader.Name="StatisticsInfo")&(textreader.NodeType="endelement")  q
                            i textreader.Name'="" s statisticsDesc=textreader.Name
                            i textreader.NodeType="chars"
                            {
                                i $g(statisticsDesc)="" s statisticsDesc=textreader.Value
                                d statisticsData.SetAt(textreader.Value,statisticsDesc)
                            }
                            
                            
                        }
                        d statisticsList.Insert(statisticsData)
                        if (textreader.MoveToAttributeName("Value"))  
                    }
                    if (textreader.Name = "PDAStyle") && (textreader.NodeType'="endelement")
                    {
                        while textreader.Read()
                        {
                            if (textreader.Name="PDAStyle")&(textreader.NodeType="endelement")  q
                            if (textreader.Name = "IsHide") && (textreader.NodeType'="endelement")
                            {
                                d textreader.Read()
                                s PdaIsHide=textreader.Value
                                ;i PdaIsHide="true" s PdaIsHide="false"
                            }   
                        }
                    }
                    //CascadingInfo级联标志
                    s ElementSetData=##class(%ArrayOfDataTypes).%New()
                    if (textreader.Name = "CascadingInfo") && (textreader.NodeType'="endelement")
                    {
                        s SetDataList=##class(%ListOfDataTypes).%New()
                        s SetData=##class(%ArrayOfDataTypes).%New()
                        s CascadingInfo="CascadingInfo"
                        d SetData.SetAt(FormName,"FormName")
                        while textreader.Read()
                        {
                            if (textreader.Name = "CascadingInfo") && (textreader.NodeType="endelement") s CascadingInfo="" q
                            
                            if (textreader.Name="AfterChangeEvent")&(textreader.NodeType'="endelement")
                            {
                                s SetData=##class(%ArrayOfDataTypes).%New()
                            }
                            
                           if (textreader.Name = "ChangeElementList") && (textreader.NodeType'="endelement")
                            {
                                s changeList=##class(%ListOfDataTypes).%New()
                                s changeData=##class(%ArrayOfDataTypes).%New()
                                d changeData.SetAt("","Type")
                                d changeData.SetAt("","Val")
                                while textreader.Read()
                                {
                                    if (textreader.Name="ChangeElementList")&(textreader.NodeType="endelement")  q
                                    if (textreader.Name="ChangeElement")&(textreader.NodeType'="endelement")
                                    {
                                        s changeData=##class(%ArrayOfDataTypes).%New()
                                        d changeData.SetAt("","Type")
                                    }
                                    
                                    i textreader.Name'="" s SetDesc=textreader.Name
                                    i textreader.NodeType="chars"
                                    {
                                        i $g(SetDesc)="" s SetDesc=textreader.Value
                                        s typeDesc=changeData.GetAt("Type")
                                        s textTmpData=textreader.Value
                                        i SetDesc="Type" s textTmpData=$s(typeDesc="":textTmpData,1:textTmpData_","_typeDesc)
                                        d changeData.SetAt(textTmpData,SetDesc)
                                    }
                                    if (textreader.Name="ChangeElement")&(textreader.NodeType="endelement")
                                    {
                                        d changeList.Insert(changeData)
                                    }
                                }
                                d SetData.SetAt(changeList,"ChangeList")
                            }
                            if (textreader.Name = "Val") && (textreader.NodeType'="endelement")
                            {
                                d textreader.Read()
                                d SetData.SetAt(textreader.Value,"Val")
                            }
                            if (textreader.Name = "Val2") && (textreader.NodeType'="endelement")
                            {
                                d textreader.Read()
                                d SetData.SetAt(textreader.Value,"Val2")
                            }
                            if (textreader.Name = "Sign") && (textreader.NodeType'="endelement")
                            {
                                d textreader.Read()
                                d SetData.SetAt(textreader.Value,"Sign")
                            }
                            if (textreader.Name = "OnlySatisfyFire") && (textreader.NodeType'="endelement")
                            {
                                d textreader.Read()
                                d ElementSetData.SetAt(textreader.Value,"OnlySatisfyFire")
                            }
                            if (textreader.Name = "AllSatisfyFire") && (textreader.NodeType'="endelement")
                            {
                                d textreader.Read()
                                d ElementSetData.SetAt(textreader.Value,"AllSatisfyFire")
                            }
                            if (textreader.Name="AfterChangeEvent")&(textreader.NodeType="endelement")
                            {
                                d SetData.SetAt($g(FormName),"FormName")
                                d SetDataList.Insert(SetData)
                            }               
                        }
                    }
                    if (textreader.Name="CascadingInfo")&(textreader.NodeType="endelement")
                    {
                        d ElementSetData.SetAt($g(SetDataList),"SetDataList")
                        d ElementSetData.SetAt($g(FormName),"FormName")
                        //RadioElement_508 多个重复问题---只取第一个
                        i ($g(FormName)'="")&&($g(tempFormName)[$g(FormName)) 
                        e  d ElementSets.Insert(ElementSetData)
                        
                        s tempFormName=$g(tempFormName)_"^"_$g(FormName)
                    }
                    s isq1 = ((textreader.NodeType="endelement") && (textreader.Name = "ElementBase"))
                    s isq2 = (textreader.Name = "Elements")
                    quit:isq1||isq2
                }
                //w $g(PdaIsHide),"-",$g(Id),!
                //一个ElementBase结束，如果存在保存字段或者数据源，则是需要取数据控件，保留
                if (PdaIsHide="false")||(SaveField'="")||(DataSourceRef'="")||(NameText="LOC")||($g(Element)="ContainerElement")||(($g(Element)="ButtonElement")&&($g(FoundationJS)'["Print")&&($g(FoundationJS)'["Save")) //&&($g(NameText)["保存"))
                {
                    i IsDynamicTitle="true"{
                        s curHead = $p(currHeadDr," ",2+dynaNum)
                        s curHead = $p(curHead,"-",2)
                        s NameText=curHead
                        ;w NameText,!
                        s dynaNum = dynaNum+1
                    }
                    s ElementBaseValue=##class(%ArrayOfDataTypes).%New()
                    d ElementBaseValue.SetAt($g(Id),"ElementId")
                    d ElementBaseValue.SetAt($g(SaveField),"SaveField")
                    d ElementBaseValue.SetAt($g(DataSourceRef),"DataSourceRef")
                    i $g(Element)="MutiLableElement" s Element="LableElement"
                    d ElementBaseValue.SetAt($g(Element),"ElementType")
                    d ElementBaseValue.SetAt($g(NameText),"NameText")
                    d ElementBaseValue.SetAt($g(FormName),"FormName")
                    d ElementBaseValue.SetAt($g(ToolTipText),"ToolTipText")
                    d ElementBaseValue.SetAt($g(OprationItemList),"OprationItemList")
                    d ElementBaseValue.SetAt($g(IsHide),"IsHide")
                    d ElementBaseValue.SetAt($g(Disable),"Disable")
                    d ElementBaseValue.SetAt($g(ParentId),"ParentId")
                    d ElementBaseValue.SetAt($g(Required),"Required")
                    d ElementBaseValue.SetAt($g(MEName),"MEName")
                    d ElementBaseValue.SetAt($g(PointLen),"PointLen")
                    d ElementBaseValue.SetAt($g(GatherEffects),"GatherEffects")
                    d ElementBaseValue.SetAt($g(GatherImportMapEffects),"GatherImportMapEffects")
                    
                    d ElementBaseValue.SetAt($g(DataSourceRefInfo),"DataSourceRefInfo")
                    d ElementBaseValue.SetAt($g(Signature),"Signature")
                    d ElementBaseValue.SetAt($g(SignatureAuto),"SignatureAuto")
                    
                    d ElementBaseValue.SetAt($g(DoctorAdviceRule),"DoctorAdviceRule")
                    s DoctorAdviceRuleLinkNo=""
                    f DoctorAdviceRulei=1:1:$l($g(DoctorAdviceRule),",/,") d
                    .s DoctorAdviceRulet=$p($g(DoctorAdviceRule),",/,",DoctorAdviceRulei)
                    .i ($g(DoctorAdviceRuleLinkNo)'="") s DoctorAdviceRuleLinkNo=DoctorAdviceRuleLinkNo_",/,"
                    .s DoctorAdviceRuleLinkNo=$g(DoctorAdviceRuleLinkNo)_$p(DoctorAdviceRulet,"!",2)
                    d ElementBaseValue.SetAt($g(DoctorAdviceRuleLinkNo),"DoctorAdviceRuleLinkNo")
                    d ElementBaseValue.SetAt($g(FoundationJS),"FoundationJS")
                    //跳转用
                    d ElementBaseValue.SetAt($g(BindingTemplateID),"BindingTemplateID") 
                    d ElementBaseValue.SetAt($g(GatherImportMapEffects),"GatherImportMapEffects")
                    d ElementBaseValue.SetAt($g(CallBackReturnMapEffects),"CallBackReturnMapEffects")
                    d ElementBaseValue.SetAt($g(CallBackEffects),"CallBackEffects")
                    d ElementBaseValue.SetAt($g(containerFlag),"containerFlag")
                    //新增MAX和MIN的Waring和Error
                    d ElementBaseValue.SetAt($g(MaxWarning),"MaxWarning")
                    d ElementBaseValue.SetAt($g(MinWarning),"MinWarning")
                    d ElementBaseValue.SetAt($g(MaxError),"MaxError")
                    d ElementBaseValue.SetAt($g(MinError),"MinError")
                    
                    d ElementBaseValue.SetAt(..getAiFlag(emrCode,NameText),"aiFlag")
                    
                    s tmpParentId=$G(ParentId)
                    i $G(tmpParentId)'="" 
                    {
                        s getFlag=1
                        while getFlag
                        {
                            i $d(containerId(tmpParentId))  d
                            .d ElementBaseValue.SetAt($g(tmpParentId),"containerId")
                            .s getFlag=0
                            s tmpParentId=$g(parent(tmpParentId))
                            i tmpParentId="" s getFlag=0
                        }
                    }               
                    i $g(ParentId)'=""  d
                    .i $d(tmp("Id","is"_ParentId)) d
                    ..s ParentHisde=$p(tmp("Id","is"_ParentId),"^",1),ParentDisable=$p(tmp("Id","is"_ParentId),"^",2)
                    ..;i ParentHisde'=""&&($g(IsHide)="")  d ElementBaseValue.SetAt($g(ParentHisde),"IsHide")
                    ..;i ParentDisable'=""&&($g(Disable)="")  d ElementBaseValue.SetAt($g(ParentDisable),"Disable")
                    s tmp("Id","is"_Id)=$g(IsHide)_"^"_$g(Disable)
                    s containerFlag="",GatherEffects="",GatherImportMapEffects="",PdaIsHide="true",MEName="",ParentId="",IsHide="",Disable="",CallBackEffects="",CallBackReturnMapEffects="",Required="",BindingTemplateID="",Signature="",SignatureAuto=""
                    s IsDynamicTitle="false"
                    i $g(ToolTipText)'="" s ToolTipText=""
                    i episodeId'="" s firstVlue=##class(NurMp.TemplateSet).GetValue($g(DataSourceRef),episodeId)
                    ;i episodeId'="" s firstVlue=""
                    s DefaultValue=""
                    i objRecord'=""&&(SaveField'="") 
                    {
                        s DefaultValue=$ZOBJPROPERTY(objRecord,SaveField)
                        i (($g(Element)["DropRadioElement")||($g(Element)["DropListElement"))&&(DefaultValue'="[]")&&(DefaultValue'="")  
                        {
                            s DefaultValue=$replace(DefaultValue,"[","")
                            s DefaultValue=$replace(DefaultValue,"]","")
                            s DefaultValueObj=##class(Nur.PDA.JSON).Decode(DefaultValue)
                            s DefaultValue=DefaultValueObj.GetAt("Text")
                            i OprationItemStr'[$g(DefaultValue)&&($g(DefaultValue)'="") s DefaultValue=""
                            
                        }
                        i $g(Element)["Check"&&(DefaultValue'="[]")&&(DefaultValue'="")
                        {
                            i $g(Element)["DropCheckboxElement"
                            {
                                s DefaultValueList=##class(Nur.PDA.JSON).Decode(DefaultValue)
                                s DefaultValueStr=""
                                s key=DefaultValueList.Next("")
                                while(key'="")
                                {
                                    s DefaultValueData=DefaultValueList.GetAt(key)
                                    s DefaultValueText=DefaultValueData.GetAt("Text")
                                    s DefaultValueStr=$s(DefaultValueStr="":DefaultValueText,1:DefaultValueStr_","_DefaultValueText)
                                    s key=DefaultValueList.Next(key)
                                }
                                s DefaultValue=DefaultValueStr
                            }else
                            {
                                i DefaultValue[NameText s DefaultValue=NameText
                                e  s DefaultValue=""
                            }
                            
                        }
                        
                        //LMS
                        i $g(Element)["Radio"&&($g(Element)'["Drop")&&(DefaultValue'="[]")&&(DefaultValue'="")
                        {
                            
                            s DefaultValue=$replace(DefaultValue,"[","")
                            s DefaultValue=$replace(DefaultValue,"]","")
                            s DefaultValueData=##class(Nur.PDA.JSON).Decode(DefaultValue)
                            s DefaultValueText=DefaultValueData.GetAt("Text")
                            s DefaultValue=DefaultValueText
                        }
                    }else{
                        i SaveField="CareDate" s DefaultValue=$zd(+$h,3)
                        i SaveField="CareTime" s DefaultValue=$zt($p($h,",",2),2)
                    }
                    i $g(firstVlue)'=""&&(id="") s DefaultValue=firstVlue
                    i DefaultValue="[]" s DefaultValue=""
                    i DefaultValue["CA" 
                    {
                        s DefaultValue=$replace(DefaultValue,"CA","")
                        s DefaultValue=$p(DefaultValue,"*")
                    }
                    i (headDrItem'="")&&(FormName=headDrItem)&&(id="") s DefaultValue=currHeadDr
                    d ElementBaseValue.SetAt($g(DefaultValue),"DefaultValue")
                    
                    i $g(Element)="RadioElement"||($g(Element)="CheckElement"){
                        i lastSaveItem=$g(SaveField)||(lastSaveItem=""){
                            d RadioElementList.Insert(ElementBaseValue)
                            d RadioElementValue.SetAt($g(Element),"ElementType")
                            d RadioElementValue.SetAt($g(SaveField),"SaveField")
                            s NameTextTmp=NameText
                            i $g(LableFor)'=""  d
                            .i $d(tmpName("Id"," "_LableFor))  d
                            ..s NameTextTmp=tmpName("Id"," "_LableFor)
                            d RadioElementValue.SetAt($g(NameTextTmp),"NameText")
                        }else{
                            
                            i RadioElementList.Count()'=0
                            {
                                d RadioElementValue.SetAt($g(RadioElementList),"RadioElementList")
                                d ElementBaseArray.Insert(RadioElementValue)
                                s RadioElementList=##class(%ListOfDataTypes).%New()
                                s RadioElementValue=##class(%ArrayOfDataTypes).%New()
                                d RadioElementList.Insert(ElementBaseValue)
                                d RadioElementValue.SetAt($g(Element),"ElementType")
                                d RadioElementValue.SetAt($g(SaveField),"SaveField")
                                s NameTextTmp=NameText
                                i $g(LableFor)'=""  d
                                .i $d(tmpName("Id"," "_LableFor))  d
                                ..s NameTextTmp=tmpName("Id"," "_LableFor)
                                d RadioElementValue.SetAt($g(NameTextTmp),"NameText")
                            }else{
                                d RadioElementList.Insert(ElementBaseValue)
                                d RadioElementValue.SetAt($g(Element),"ElementType")
                                d RadioElementValue.SetAt($g(SaveField),"SaveField")
                                s NameTextTmp=NameText
                                i $g(LableFor)'=""  d
                                .i $d(tmpName("Id"," "_LableFor))  d
                                ..s NameTextTmp=tmpName("Id"," "_LableFor)
                                d RadioElementValue.SetAt($g(NameTextTmp),"NameText")
                            }
                        }
                    }else{
                        i RadioElementList.Count()'=0
                        {
                            d RadioElementValue.SetAt($g(RadioElementList),"RadioElementList")
                            d ElementBaseArray.Insert(RadioElementValue)
                            s RadioElementList=##class(%ListOfDataTypes).%New()
                            s RadioElementValue=##class(%ArrayOfDataTypes).%New()
                        }
                        d ElementBaseArray.Insert(ElementBaseValue)
                    }
                    i ($g(Element)="RadioElement"||($g(Element)="CheckElement"))&&(lastSaveItem="") s lastSaveItem=$g(SaveField)
                    i SaveField'=""&&(lastSaveItem'="") s lastSaveItem=$g(SaveField)
                }else{
                    s IsHide="",Disable="",BindingTemplateID="",CallBackEffects="",CallBackReturnMapEffects="",IsDynamicTitle="false"
                }
            }
            elseif  ((textreader.Value = "HISUIDataTableElementPrint")||(textreader.Value = "RowToColDataTableElementPrint"))&& (textreader.NodeType = "attribute") 
            {
                //表格部分解析
                //解析元素：HISUIDataTableElementPrint，RowToColDataTableElementPrint，属性包括：Id，EveryYearFirstRecord，EveryDaySameTimeRecord，
                //EveryDayFirstRecord，IsZhuanKeDaYin，IsZhuanKeHuanzhiDaYin，IsZhuanKeJiluDaYin，KeShiGeShi，ShowNumerValue，HISUIColumnInfo，
                //HISUIColumnInfo，RowToColColumnInfo，field，TemplateIndentity，DataReference
                
                s (TableId,TableTemplateIndentity,EveryYearFirstRecord,EveryYearFirstRecord,EveryDayFirstRecord,EveryDaySameTimeRecord,EveryPageFirstRowShowFullDateTime,IsZhuanKeDaYin,IsZhuanKeHuanzhiDaYin,IsZhuanKeHuanzhiDaYin,KeShiGeShi,DataReference)=""
                s fieldsArray=##class(%ListOfDataTypes).%New()  //存储所有field集合 
                
                while textreader.Read()
                {
                    //表格Id
                    if (textreader.Name = "Id") && (textreader.NodeType'="endelement")
                    {
                        d textreader.Read()
                        i TableId="" s TableId=textreader.Value 
                    }
                    //表格引用模板数据TemplateIndentity
                    if (textreader.Name = "TemplateIndentity") && (textreader.NodeType'="endelement")  
                    {
                        d textreader.Read()
                        s TableTemplateIndentity=textreader.Value   
                    }
                    //日期时间显示1/4，每一年第一条记录日期格式为年-月-日，其余格日期格式为：月-日：启用true，不启用空
                    if (textreader.Name = "EveryYearFirstRecord") && (textreader.NodeType'="endelement")  
                    {
                        d textreader.Read()
                        s EveryYearFirstRecord=textreader.Value 
                    }
                    //日期时间显示2/4，同一天记录日期格式只显示第一条日期，其余只显示时间：启用true，不启用空
                    if (textreader.Name = "EveryDayFirstRecord") && (textreader.NodeType'="endelement")  
                    {
                        d textreader.Read()
                        s EveryDayFirstRecord=textreader.Value  
                    }
                    //日期时间显示3/4，同一日期，同一时间点的日期格式为第一条记录显示日期，时间，其余不显示：启用true，不启用空
                    if (textreader.Name = "EveryDaySameTimeRecord") && (textreader.NodeType'="endelement")  
                    {
                        d textreader.Read()
                        s EveryDaySameTimeRecord=textreader.Value   
                    } 
                    //日期时间显示4/4，每页的第一条显示完整的日期时间：启用true，不启用空
                    if (textreader.Name = "EveryPageFirstRowShowFullDateTime") && (textreader.NodeType'="endelement")  
                    {
                        d textreader.Read()
                        s EveryPageFirstRowShowFullDateTime=textreader.Value    
                    }
                    //转科显示1/4，转科打印：启用true，不启用空
                    if (textreader.Name = "IsZhuanKeDaYin") && (textreader.NodeType'="endelement")  
                    {
                        d textreader.Read()
                        s IsZhuanKeDaYin=textreader.Value   
                    }
                    //转科显示2/4，转科换页打印：换页true，不换页空
                    if (textreader.Name = "IsZhuanKeHuanzhiDaYin") && (textreader.NodeType'="endelement")  
                    {
                        d textreader.Read()
                        s IsZhuanKeHuanzhiDaYin=textreader.Value    
                    }
                    //转科显示3/4，按转科记录转科打印true，按保存记录转科打印空
                    if (textreader.Name = "IsZhuanKeJiluDaYin") && (textreader.NodeType'="endelement")  
                    {
                        d textreader.Read()
                        s IsZhuanKeJiluDaYin=textreader.Value   
                    } 
                    //转科显示3/4，显示当前科室名称为空，A-->B前一科室到后一科室为2，A-->B-->C显示所有转过科室为3
                    if (textreader.Name = "KeShiGeShi") && (textreader.NodeType'="endelement")  
                    {
                        d textreader.Read()
                        s KeShiGeShi=textreader.Value   
                    }
                    //数据源标志，不为空则不取表中数据，改取数据源数据
                    if (textreader.Name = "DataReference") && (textreader.NodeType'="endelement")  
                    {
                        d textreader.Read()
                        s DataReference=textreader.Value    
                    }
                    //表格中每个字段，一个Fields标签一个字段
                    if ((textreader.Name = "Fields")||(textreader.Name = "Rows")) && (textreader.NodeType'="endelement")
                    {
                        
                        s fieldArray=##class(%ListOfDataTypes).%New()  //存储一个field集合（多绑定元素会有两个field） 
                        
                        while textreader.Read()
                        {
                            //绑定元素fieldname
                            if (textreader.Name = "field") && (textreader.NodeType'="endelement")
                            {
                                d textreader.Read()
                                s field=textreader.Value                        
                            }
                            //所有选择项，单选/多选/下拉单选/下拉多选等，不显示描述，显示值属性
                            if (textreader.Name = "ShowNumerValue") && (textreader.NodeType'="endelement")  
                            {
                                d textreader.Read()
                                s ShowNumberValue=textreader.Value  
                            }
                            //多元素绑定，显示分隔符
                            if (textreader.Name = "SplitString") && (textreader.NodeType'="endelement")  
                            {
                                d textreader.Read()
                                s SplitString=textreader.Value  
                            }
                            //一个field开始，初始化属性变量
                            if ((textreader.Name = "BandColumnInfo")||(textreader.Name = "RowToColColumnInfo")) && (textreader.NodeType'="endelement")  
                            {
                                s (field,ShowNumerValue,SplitString)=""
                            }
                            //一个field结束，插入数据
                            if ((textreader.Name = "BandColumnInfo")||(textreader.Name = "RowToColColumnInfo")) && (textreader.NodeType="endelement")  
                            {
                                if (field'="")
                                {
                                    if ('$d(TMPTablesmallvalue(TableId,$g(field))))
                                    {
                                        s fieldValue=##class(%ArrayOfDataTypes).%New()
                                        d fieldValue.SetAt($g(field),"bindName")
                                        d fieldValue.SetAt($g(ShowNumerValue),"ShowNumerValue")
                                        d fieldValue.SetAt($g(SplitString),"SplitString")
                                        d fieldArray.Insert(fieldValue)
                                        s TMPTablesmallvalue(TableId,$g(field))=""
                                        s (field,ShowNumerValue,SplitString)=""
                                    }
                                }
                            }
                            quit:((textreader.NodeType="endelement") && (textreader.Name = "Fields"))
                            quit:((textreader.NodeType="endelement") && (textreader.Name = "Rows"))
                        }
                        //Fields结束，将取出来fieldArray放到fieldsArray中
                        s fieldsValue=##class(%ArrayOfDataTypes).%New()
                        d fieldsValue.SetAt(fieldArray,"field")
                        d fieldsArray.Insert(fieldsValue)
                    }
                    s isq1 = ((textreader.NodeType="endelement") && (textreader.Name = "ElementBase"))
                    s isq2 = (textreader.Name = "Elements")
                    quit:isq1||isq2
                }
                //HISUIDataTableElementPrint结束，将取出来Table信息放到tableArray中
                s tableValue=##class(%ArrayOfDataTypes).%New()
                d tableValue.SetAt($g(TableId),"tableId")
                d tableValue.SetAt($g(TableTemplateIndentity),"TemplateIndentity")
                d tableValue.SetAt($g(EveryYearFirstRecord),"EveryYearFirstRecord")
                d tableValue.SetAt($g(EveryDayFirstRecord),"EveryDayFirstRecord")
                d tableValue.SetAt($g(EveryDaySameTimeRecord),"EveryDaySameTimeRecord")
                d tableValue.SetAt($g(EveryPageFirstRowShowFullDateTime),"EveryPageFirstRowShowFullDateTime")
                d tableValue.SetAt($g(IsZhuanKeDaYin),"IsZhuanKeDaYin")
                d tableValue.SetAt($g(IsZhuanKeHuanzhiDaYin),"IsZhuanKeHuanzhiDaYin")
                d tableValue.SetAt($g(IsZhuanKeJiluDaYin),"IsZhuanKeJiluDaYin")
                d tableValue.SetAt($g(KeShiGeShi),"KeShiGeShi")
                d tableValue.SetAt($g(DataReference),"DataReference")
                d tableValue.SetAt(fieldsArray,"fields")
                d tableArray.Insert(tableValue)
            } 
    
        }
        //TemplateIndentity是调用打印模板的界面模板TemplateIndentity，比如记录单
        if (textreader.Name = "Templates") 
        {
            while textreader.Read()
            { 
                i (textreader.Name = "TemplateIndentity") && (textreader.NodeType'="endelement")
                {
                    d textreader.Read()
                    s TemplateIndentity=textreader.Value
                }
            }
        }
        if (textreader.Name = "HandoverCfg")
        {
            s modelElemen=""
            while textreader.Read()
            { 
                if (textreader.Name="HandoverCfg")&(textreader.NodeType="endelement")  q
                if (textreader.Name = "Sections")
                {
                    while textreader.Read()
                    {
                        if (textreader.Name="Sections")&(textreader.NodeType="endelement")  q   
                        if (textreader.Name = "TemplateSection")&(textreader.NodeType'="endelement")
                        { 
                            s aaData=##class(%ArrayOfDataTypes).%New() // InputsList RoseList
                            s InputsList=##class(%ListOfDataTypes).%New()
                            s RoseList=##class(%ListOfDataTypes).%New()
                        }   
                        i (textreader.Name = "Inputs") && (textreader.NodeType'="endelement")
                        {
                            while textreader.Read()
                            { 
                                if (textreader.Name="Inputs")&(textreader.NodeType="endelement")  q
                                i (textreader.Name = "string")&& (textreader.NodeType'="endelement")
                                {
                                    //安全组控制的元素
                                    s InputData=##class(%ArrayOfDataTypes).%New()
                                    d textreader.Read()
                                    d InputData.SetAt(textreader.Value,"Code")
                                }
                                i (textreader.Name = "string")&& (textreader.NodeType="endelement")
                                {
                                    d InputsList.Insert(InputData)
                                }
                    
                            }
                        }
                        i (textreader.Name = "Roles") && (textreader.NodeType'="endelement")
                        {
                            while textreader.Read()
                            { 
                                if (textreader.Name="Roles")&(textreader.NodeType="endelement")  q
                                s modelElement="",SecureGroup=""
                                i (textreader.Name = "string")&& (textreader.NodeType'="endelement")
                                {
                                    s RoseData=##class(%ArrayOfDataTypes).%New()
                                    d textreader.Read()
                                    d RoseData.SetAt(textreader.Value,"Code")
                                }
                                i (textreader.Name = "string")&& (textreader.NodeType="endelement")
                                {
                                    d RoseList.Insert(RoseData)
                                }
                            }
                        }                           
                        if (textreader.Name = "TemplateSection")&(textreader.NodeType="endelement")
                        { 
                            d aaData.SetAt(InputsList,"InputsList")
                            d aaData.SetAt(RoseList,"RoseList")
                            d StrictCodeList.Insert(aaData)
                        }
                    }
                }
                
            }
        }   
    }
    ///元素在最后单子一个的情况
    i RadioElementList.Count()'=0
    {
        d RadioElementValue.SetAt($g(RadioElementList),"RadioElementList")
        d ElementBaseArray.Insert(RadioElementValue)
        s RadioElementList=##class(%ListOfDataTypes).%New()
        s RadioElementValue=##class(%ArrayOfDataTypes).%New()
    }
    //获取单据第一次记录的ID
    s firstIdList=##class(%ListOfDataTypes).%New()
    i episodeId'="" d
    .;s emrCodeStr="DHCNURBarthelLR^DHCNURDDFXPGJHLJLDLR^DHCNURGLHTFXYSPGJHLCSLR^DHCNURYCFXPGJHLJLDCRHZLR"
    .;s len=$l(emrCodeStr,"^")
    .;f i=1:1:len  d
    .;.s emrCode=$p(emrCodeStr,"^",i)
    .;.q:emrCode=""
    .s id=""
    .f  s id=$o(^CF.NUR.MNIS.EmrModelD(id)) q:id=""  d
    ..s modelData=^CF.NUR.MNIS.EmrModelD(id)
    ..s sort=$listget(modelData,4)
    ..i sort="" s sort=999999
    ..s modelID(sort,id)=1
    .s sort=""
    .f  s sort=$o(modelID(sort)) q:sort=""  d
    ..s modelID=""
    ..f  s modelID=$o(modelID(sort,modelID)) q:modelID=""  d
    ...s modelData=^CF.NUR.MNIS.EmrModelD(modelID)
    ...s emrCode=$listget(modelData,3)
    ...s UemrCode=$ZConvert(emrCode,"U")
    ...s TCIdent=##class(NurMp.Template).GetTCIndentity(UemrCode)
    ...s TCIdent=$ZConvert(TCIdent,"U")
    ...s firstData=##class(%ArrayOfDataTypes).%New()
    ...s firstId=##class(Nur.MNISV3.Service.NurEmr).GetFirstId(emrCode,episodeId)
    ...d firstData.SetAt(emrCode,"EmrCode")
    ...d firstData.SetAt(firstId,"RecId")
    ...d firstData.SetAt(TCIdent,"GuId")
    ..;w emrCode,!
    ..d firstIdList.Insert(firstData)
    
    
    s inputValue=##class(%ArrayOfDataTypes).%New()
    d inputValue.SetAt($g(TemplateIndentity),"TemplateIndentity")
    d inputValue.SetAt($g(ElementBaseArray),"ElementBases")
    d inputValue.SetAt($g(ElementSets),"ElementSets")
    d inputValue.SetAt($g(statisticsList),"statisticsList")
    
    s dataValue=##class(%ArrayOfDataTypes).%New()
    d dataValue.SetAt(inputValue,"Input")
    d dataValue.SetAt(tableArray,"Table")
    i objRecord'="" d objRecord.%Close()
    s re = ##class(%ArrayOfDataTypes).%New()
    s funList=..GetAll("","")
    d re.SetAt("","msg")
    d re.SetAt("0","status")
    d re.SetAt(StrictCodeList,"StrictCodeList")
    d re.SetAt(dataValue,"data")
    d re.SetAt(firstIdList,"firstIdList")
    d re.SetAt(funList,"funList")
    q ##class(Nur.MNISV3.Common.JSON).Encode(re,simplification)
    q re
        
errorGetPrintXmlValues
    
    s msg=$ze
    
    q ##class(NurMp.ErrorMsg).ReturnMsgJson(msg,"-1")
}

Query GetNurEmrConfigPDA(locId As %String, emrCode As %String) As %Query(ROWSPEC = "itemDesc:%String,itemCode:%String,itemType,itemdeValue,itemValue:%String,width,height,titleHiddeFlag,fontSize,ModelSort,PatInfo,mustFill,singleCheck,editFlag,toastStr,editCondition,jModelKey,subRowId,editType,editItem,Unit,imageName")
{
}

ClassMethod GetNurEmrConfigPDAExecute(ByRef qHandle As %Binary, locId As %String, emrCode As %String) As %Status
{
    
    Set repid=$I(^CacheTemp)
    s ind=1
    //d ##class(%ResultSet).RunQuery("Nur.MNIS.Service.NurEmrConfig","GetNurEmrConfigPDA","","DHCNurGradeTourPda")
            i emrCode="DHCNurGradeTourPda" s sortid=1
            i emrCode="DHCNurInfusionTourPda" s sortid=2
            s sort=""
            f  s sort=$o(^CF.NUR.MNIS.TourModelItemSetI("ModelSort",sort)) q:sort=""  d
            .s childId=""
            .f  s childId=$o(^CF.NUR.MNIS.TourModelItemSetI("ModelSort",sort,sortid,childId)) q:childId=""  d
            ..s obj=##class(CF.NUR.MNIS.TourModelItemSet).%OpenId(sortid_"||"_childId)
            ..s itemType=obj.OperationType
            ..s itemDesc=obj.OperationName
            ..s itemValue=obj.OperationContent
            ..s itemCode=obj.OperationCode
            ..s ModelSort=obj.OperationSort    //排序用
            ..s editFlag=obj.OperationCanOrNo   //是否可编辑
            ..s itemdeValue=obj.OperationDefault  //默认值    
            ..s width=""
            ..s height=""
            ..s titleHiddeFlag=""
            ..s fontsize=""
            ..s PatInfo=""
            ..s mustFill=""
            ..//:PatInfo:mustFill:singleCheck:editFlag:toastStr:editCondition:jModelKey:subRowId:editType:editItem:Unit:imageName:"
            ..s singleCheck=""
            ..s toastStr=""
            ..s editCondition=""
            ..s jModelKey=""
            ..s subRowId=""
            ..s editType=""
            ..s editItem=""
            ..s Unit=""
            ..s imageName=""
            ..d OutPutTourModel
            
            i ('$d(^CacheTemp(repid,1))) m ^CacheTemp(repid)=^DHCCLSet("PDA","Tour",emrCode)
    
    Set qHandle=$lb(0,repid,0)
    Quit $$$OK
OutPutTourModel
    set Data=$lb(itemDesc,itemCode,itemType,itemdeValue,itemValue,width,height,titleHiddeFlag,fontsize,ModelSort,"","false",singleCheck,editFlag,"","","","","","","")
    Set ^CacheTemp(repid,ind)=Data
    Set ind=ind+1
    quit
}

ClassMethod GetNurEmrConfigPDAFetch(ByRef qHandle As %Binary, ByRef Row As %List, ByRef AtEnd As %Integer = 0) As %Status [ PlaceAfter = GetNurEmrConfigPDAExecute ]
{
    Set AtEnd=$LIST(qHandle,1)
    Set repid=$LIST(qHandle,2)
    Set ind=$LIST(qHandle,3)
    Set ind=$o(^CacheTemp(repid,ind))
    If ind="" {             // if there are no more rows, finish fetching
        Set AtEnd=1
        Set Row=""
    }
    Else      {         
        Set Row=^CacheTemp(repid,ind)
    }
    s qHandle=$lb(AtEnd,repid,ind)
    Quit $$$OK
}

ClassMethod GetNurEmrConfigPDAClose(ByRef qHandle As %Binary) As %Status [ PlaceAfter = GetNurEmrConfigPDAExecute ]
{
    Set repid=$LIST(qHandle,2)
    Kill ^CacheTemp(repid)
    Quit $$$OK
}

/// w ##class(Nur.MNISV3.Service.NurEmrConfig).GetXmlDocument("DHCNURZLNLPG","","47607")
ClassMethod GetXmlDocument(emrCode, id, episodeId = "")
{
    n (emrCode,id,episodeId)

    s msg="",msgcode="999999",status="0" //定义初始值
 
    s TemplateIndentity=""   //input取值，从直接调用打印模板界面取值记录单，则是列表界面
    
    s tableArray=##class(%ListOfDataTypes).%New()  //存储所有table集合
    s ElementBaseArray=##class(%ListOfDataTypes).%New()  //存储所有input元素集合
    
    //取模板xml
    set PrintTemplateId=$o(^NurMp.TemplateI("Indentity"," "_$ZConvert(emrCode,"U"),""))
    set PrintTemplate=##class(NurMp.Template).%OpenId(PrintTemplateId)
    set data = PrintTemplate.Content
      
    s json=##class(%ArrayOfDataTypes).%New()
    d json.SetAt($g(msg),"msg")
    d json.SetAt($g(msgcode),"msgcode")
    d json.SetAt($g(status),"status")
    s docContent = $zcvt(data.Read(),"I","UTF8")
    s docContent=$replace(docContent,"\","")
    d json.SetAt(docContent,"data")
    q json
    q docContent
}

/// creator:nw
/// createdate:20181229
/// input:""
/// output:-1 失败 0 成功
/// description: 获取所有表达式数据
/// other: w ##class(Nur.PDA.NurEmrConfig).getAll()
ClassMethod GetAll(type As %String, ip As %String)
{
    s MsgObj=##class(%ArrayOfDataTypes).%New()
    s Infos = ##class(%ListOfDataTypes).%New()
    s repid=""
    s Msg="",Status="0" //定义初始值
    
    if (type = "maintain")
    {
        s locksucess = ##class(NurMp.MedicalExpressions).EditLock(ip)
        if (locksucess = -99)
        {
            d MsgObj.SetAt("其他客户端正在维护","msg")
            d MsgObj.SetAt("1","status")
            d MsgObj.SetAt(Infos,"data")
            
            q ##class(NurMp.ErrorMsg).Encode(MsgObj)
        }
            
    }
    else
    {
        i $d(^NurMp.MedicalExpressionsD) > 1
        {
            s repid = ##class(NurMp.MedicalExpressions).ApplyLock()
        }
    }
    
    
    s id=""
    f  s id=$o(^NurMp.MedicalExpressionsD(id)) q:id=""  d
    .s a=##class(NurMp.MedicalExpressions).%OpenId(id)
    .s InfoId=##class(%ArrayOfDataTypes).%New()
    .d InfoId.SetAt(id,"Id")
    .d InfoId.SetAt(a.Name,"Name")
    .d InfoId.SetAt(a.Content,"Content")
    .d InfoId.SetAt(repid,"RepId")
    .d InfoId.SetAt(a.FormatFun,"FormatFun")
    .d InfoId.SetAt(a.DataType,"DataType")
    .s DescriptionItems=$tr(a.DescriptionItems,"{""}","")
    .s l=$l(DescriptionItems,",")
    .s Desc=##class(%ArrayOfDataTypes).%New()
    .f i=1:1:l d
    ..s itm=$p($p(DescriptionItems,",",i),":",1)
    ..q:itm=""
    ..s val=$p($p(DescriptionItems,",",i),":",2)
    ..d Desc.SetAt(val,itm)
    .d InfoId.SetAt(Desc,"DescriptionItems")
    .d Infos.Insert(InfoId)
    q Infos
}

/// EH 表头变更记录单
ClassMethod GetChangeHeadObj(emrCode, admId, userId) As %ArrayOfDataTypes
{
    n (emrCode,admId,userId,%session)
    s changeHeadObj=##class(%ArrayOfDataTypes).%New()
    s listCode=##class(Nur.MNISV3.Service.Config).GetTemplateListCode(admId,emrCode)
    s changeHeadItem=..GetListChangeHeadItem(listCode)
    q:(changeHeadItem="") changeHeadObj
    s changeHeadList=..GetChangeHeadList(emrCode,admId,userId)
    s FormName=$p($p(changeHeadItem,"^",3),":",2)
    d changeHeadObj.SetAt(FormName,"FormName")
    d changeHeadObj.SetAt(changeHeadList,"DTTItems")
    q changeHeadObj
}

/// w ##class(Nur.MNISV3.Service.NurEmrConfig).GetChangeHeadList("DHCNURHLJLDLR",27,17451)
ClassMethod GetChangeHeadList(emrCode, admId, userId) As %ListOfDataTypes
{
    n (emrCode,admId,userId,%session)
    s changeHeadList=##class(%ListOfDataTypes).%New()
    s listCode=##class(Nur.MNISV3.Service.Config).GetTemplateListCode(admId,emrCode)
    s listGuid=##class(NurMp.Template).GetTCIndentity(listCode)
    s changeHeadItem=..GetListChangeHeadItem(listCode)
    q:(listGuid="")||(changeHeadItem="") changeHeadList
    s datapost="{""templateVersionGuid"":""9abb3df8637a4d6b9514f9b31a66b6a8"",""EpisodeID"":""27""}"
    s datapost=$replace(datapost,"""9abb3df8637a4d6b9514f9b31a66b6a8""",""""_listGuid_"""")
    s datapost=$replace(datapost,"""27""",""""_admId_"""")
    i ('$d(%session)) s openSessionFlag=##class(Nur.OEQtyImpToNurRec).OpenSession(userId,##class(Nur.MNISV3.Service.Session).GetPatLocID(admId))
    s ret=##class(Nur.OEQtyImpToNurRec).ImpToNurRec("NurMp.TemplateSet","GetCodeList",datapost)
    i ($d(openSessionFlag)) d ##class(Nur.OEQtyImpToNurRec).CloseSession()
    i ('$isobject(ret)) s ret=##class(NurMp.Json).Decode(ret)
    i ($isobject(ret)) d
    .s data=ret.GetAt("data")
    .q:('$isobject(data))
    .s item=$p(changeHeadItem,"^",2)
    .s change=data.GetAt(item)
    .s select=""
    .s values=change.GetAt("values")
    .s b=values.Count()
    .f a=1:1:b d
    ..s c=values.GetAt(a)
    ..s select=c.GetAt("Text")
    .s source=change.GetAt("source")
    .s l=source.Count()
    .f i=1:1:l d
    ..s s=source.GetAt(i)
    ..d s.SetAt(s.GetAt("Text")=select,"SelectState")
    ..d s.SetAt($e(s.GetAt("Text"),1,17)_s.GetAt("Value")_$e(s.GetAt("Text"),20,*),"SelectValue")
    ..d changeHeadList.Insert(s)
    q changeHeadList
}

/// w ##class(Nur.MNISV3.Service.NurEmrConfig).GetListChangeHeadItem("DHCNURHLJLD")
ClassMethod GetListChangeHeadItem(listCode) As %String
{
    n (listCode)
    s changeHeadItem=""
    s guid=##class(NurMp.Template).GetTCIndentity(listCode)
    s tid=$o(^NurMp.TemplateI("TCIndentity"," "_$zcvt(guid,"U"),""),-1)
    q:(tid="") changeHeadItem
    s obj=##class(NurMp.Template).%OpenId(tid)
    s xml=obj.Content
    d obj.%Close()
    s sc=##class(%XML.TextReader).ParseStream(xml,.reader,"",27,1023,"",1)
    i ($$$ISERR(sc)) s reader=""
    q:(reader="") changeHeadItem
    while (reader.Read()) {
        i (reader.Name="ElementBase")&&(reader.NodeType'="endelement") {
            d reader.MoveToAttributeName("type")
            i (reader.Value="DropListElement") {
                s tmpItem="",isChangeHead=0
                while (reader.Read()) {
                    i (reader.Name="FormName")&&(reader.NodeType="element") {
                        while (reader.Read()) {
                            i (reader.Name="")&&(reader.NodeType="chars") {
                                s $p(tmpItem,"^",2)=reader.Value
                            }
                            q:(reader.Name="FormName")&&(reader.NodeType="endelement")
                        }
                    } elseif (reader.Name="QueryBindingInfo")&&(reader.NodeType'="endelement") {
                        while (reader.Read()) {
                            i (reader.Name="Field")&&(reader.NodeType="element") {
                                while (reader.Read()) {
                                    i (reader.Name="")&&(reader.NodeType="chars") {
                                        s $p(tmpItem,"^",3)=reader.Value
                                    }
                                    q:(reader.Name="Field")&&(reader.NodeType="endelement")
                                }
                            }
                            q:(reader.Name="QueryBindingInfo")&&(reader.NodeType="endelement")
                        }
                    } elseif (reader.Name="DataInfo")&&(reader.NodeType'="endelement") {
                        while (reader.Read()) {
                            i (reader.Name="SaveField")&&(reader.NodeType="element") {
                                while (reader.Read()) {
                                    i (reader.Name="")&&(reader.NodeType="chars") {
                                        s $p(tmpItem,"^",1)=reader.Value
                                    }
                                    q:(reader.Name="SaveField")&&(reader.NodeType="endelement")
                                }
                            }
                            q:(reader.Name="DataInfo")&&(reader.NodeType="endelement")
                        }
                    } elseif (reader.Name="FoundationJS")&&(reader.NodeType="element") {
                        while (reader.Read()) {
                            i (reader.Name="")&&(reader.NodeType="chars") {
                                i (reader.Value="DynamicTableTitleDropListChange") s isChangeHead=1
                            }
                            q:(reader.Name="FoundationJS")&&(reader.NodeType="endelement")
                        }
                    }
                    q:(reader.Name="ElementBase")&&(reader.NodeType="endelement")
                }
                i (isChangeHead=1) s changeHeadItem=tmpItem
            }
        }
    }
    d reader.%Close()
    q changeHeadItem
}

/// w ##class(Nur.MNISV3.Service.NurEmrConfig).GetCodeList("DHCNURHLJLDLR","","60000054")
ClassMethod getAiFlag(emrCode, nameText) As %String
{
    n (emrCode, nameText)
    s aiFlag=""
    s:nameText["病史提供者" aiFlag="1"
    s:nameText["入院途径" aiFlag="1"
    s:nameText["入院方式" aiFlag="1"
    s:nameText["民族" aiFlag="1"
    s:nameText["宗教" aiFlag="1"
    s:nameText["职业" aiFlag="1"
    s:nameText["婚姻" aiFlag="1"
    s:nameText["语言" aiFlag="1"
    s:nameText["文化程度" aiFlag="1"
    s:nameText["饮酒" aiFlag="1"
    s:nameText["付费方式" aiFlag="1"
    s:nameText["家族史" aiFlag="1"
    s:nameText["手术史" aiFlag="1"
    s:nameText["过敏史" aiFlag="1"
    s:nameText["体温" aiFlag="1"
    s:nameText["脉搏" aiFlag="1"
    s:nameText["呼吸" aiFlag="1"
    s:nameText["血压" aiFlag="1"
    s:nameText["意识" aiFlag="1"
    s:nameText["呼吸系统" aiFlag="1"
    s:nameText["神经系统" aiFlag="1"
    s:nameText["皮肤" aiFlag="1"
    s:nameText["身高" aiFlag="1"
    s:nameText["体重" aiFlag="1"
    s:nameText["入院宣教内容" aiFlag="1"
    
    q aiFlag
}

}
